<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
    String xm_code = request.getParameter("xm_code") == null ? "" : request.getParameter("xm_code");
    String xm_id = request.getParameter("xm_id") == null ? "" : request.getParameter("xm_id");
    String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
    String xm_flow_status = request.getParameter("xm_flow_status") == null ? "" : request.getParameter("xm_flow_status");

    boolean isAdd = "".equals(xm_id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<script type="text/javascript">
<!--
var isShow=<%=request.getParameter("isShow")%>;
//-->
</script>
<html>
	<head>
		<title><%=isAdd?"新建项目":"编辑项目" %></title>
		<link  rel="stylesheet"  href  ="<%=contextPath%>/public/swfupload/css/swfupload.css">
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/datastructs.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/sys.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/core/js/prototype.js"  ></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/attachMenu.js"></script>
		<script type="text/javascript" src="<%=contextPath%>/public/swfupload/js/Menu.js"></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/fileprogress.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/handlers.js"  ></script>
		<script  type="text/javascript"  src="<%=contextPath%>/public/swfupload/js/swfupload.queue.js"  ></script>
		<script type="text/javascript">
			var lastIndex=-1;
			var fb_lastIndex=-1;
			var adminId="";
			var adminName="";
			var customerId="";
			var customerName="";
			var company1Id="";
			var company1Name="";
			var company2Id="";
			var company2Name="";
			var xm_code_old="";
			jQuery(document).ready(function() {
				jQuery("#estimate_balance_price").next("span").children().first().blur(function(){
	       				 setCalculateValueBlur();
	   			 })  
	   			 jQuery("#estimate_manage_price").next("span").children().first().blur(function(){
       				 setCalculateValueBlur();
   				 }) 
   				 jQuery("#estimate_tax_price").next("span").children().first().blur(function(){
       				 setCalculateValueBlur();
   				 }) 
				jQuery("#searchValuec").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearchc();
			       	} 
			   	});
				jQuery("#customer_type_id").combotree({
					url:'<%=contextPath%>/springMVC/group/getSystemTypeTree?type=1',
					method:'POST',
					animate:true,
					lines:true,
					onChange:function(){
						doSearchc();
					}
				});
				jQuery("#p_dept_id").combotree({
					url:'<%=contextPath %>/springMVC/group/listDepartment',
					method:'POST',
					animate:true,
					lines:true,
					onChange:function(){
						doSearch();
					}
				});
				jQuery("#searchValue").keypress(function(e) { 
			    	// 回车键事件 
			     	if(e.which == 13) { 
			     		 doSearch();
			       	} 
			   	}); 
				if('1' == '<%=flag%>'){
					jQuery('#xmForm').form({
						onLoadSuccess:function(data){
							adminId=data.admin_id;
							adminName=data.admin_name;
							customerId=data.customer_id;
							customerName=data.customer;
							company1Id=data.company1_id;
							company1Name=data.company1;
							company2Id=data.company2_id;
							company2Name=data.company2;
							xm_code_old=data.xm_code;
						    loadGDSets();
							queueCompleteOver();
						}
					});
				   jQuery('#xmForm').form('load','<%=contextPath%>/springMVC/xm/getXM?xm_id=<%=request.getParameter("xm_id")%>&xm_flow_status=<%=request.getParameter("xm_flow_status")%>');
				}
				
				jQuery("#xm_code").blur(function() { 
					var xm_code = jQuery("#xm_code").val();
					jQuery.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/xm/checkSameXMCode?xm_code='+xm_code,
						success:function(num){
							var number = parseInt(num);
							//如果是编辑
							if('1' == '<%=flag%>'){
								if(xm_code != xm_code_old && number > 0){
									alert("该项目编号已经存在");
									jQuery("#xm_code").val(xm_code_old);
								}
							}else{
								if(number > 0){
									alert("该项目编号已经存在");
									jQuery("#xm_code").val('');
								}
							}
							
						}
					});
			   	}); 
				
				jQuery('#company1_id').combogrid({
					title:'管理公司',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageCompany?type=1",
					idField:"id",
					textField:"company_name",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'公司名称',field:'company_name',width:200,align:'center'}
					]],
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onLoadSuccess:function(rtJson){
						jQuery('#company1_id').combogrid('setValue',company1Id);
						jQuery('#company1_id').combogrid('setText',company1Name);
					}
				});
				jQuery('#company2_id').combogrid({
					title:'实施公司',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageCompany?type=2",
					idField:"id",
					textField:"company_name",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'公司名称',field:'company_name',width:200,align:'center'}
					]],
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onLoadSuccess:function(rtJson){
						jQuery('#company2_id').combogrid('setValue',company2Id);
						jQuery('#company2_id').combogrid('setText',company2Name);
					}
				});
            jQuery('#customer_id').combogrid({
					title:'客户选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/crm/listPageCustomer",
					idField:"id",
					textField:"company",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{title:'客户类别',field:'type_name',width:200,align:'center'},
						{title:'公司名称',field:'company',width:200,align:'center'},
						{title:'联系人',field:'contact',width:200,align:'center'},
						{title:'TEL',field:'tel',width:200,align:'center'}
					]],
					toolbar:"#tbc",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onChange:function(){
						var row = jQuery('#customer_id').combogrid("grid").datagrid('getSelected');
						jQuery('#customer_linkman').val(row.contact);
						jQuery('#linkman_phone').val(row.tel);
					},
					onLoadSuccess:function(rtJson){
						var row = jQuery('#customer_id').combogrid("grid").datagrid('getSelected');
						if(row != null){
							jQuery('#customer_id').val(row.id);
							jQuery('#customer_id').val(row.company);
						}
						jQuery('#customer_id').combogrid('setValue',customerId);
						jQuery('#customer_id').combogrid('setText',customerName);
					}
				});
         
			jQuery('#admin_id').combogrid({
					title:'人员选择',
					mode:"remote",
					loadMsg:'正在加载数据，请稍后......',
					panelWidth:550,
					panelHeight:400,
					url:"<%=contextPath%>/springMVC/group/listPageUser",
					idField:"id",
					textField:"truename",
					rownumbers:true,
					fitColumns:true,
					columns: [[
						{field:'id',hidden:true},
						{field:'deptId',hidden:true},
						{field:'truename',title:'姓名',width:100},
						{field:'deptName',title:'所属部门',width:100},
						{field:'privName',title:'角色',width:100}
					]],
					toolbar:"#tb",
					pageSize:10,
					pageList:[10,50,100],  
					pagination:true,
					onChange:function(){
						var row = jQuery('#admin_id').combogrid("grid").datagrid('getSelected');
						jQuery('#admin_dept_id').val(row.deptId);
						jQuery('#admin_dept').val(row.deptName);
					},
					onLoadSuccess:function(rtJson){
						var row = jQuery('#admin_id').combogrid("grid").datagrid('getSelected');
						if(row != null){
							jQuery('#admin_id').val(row.id);
							jQuery('#admin_id').val(row.truename);
						}
						jQuery('#admin_id').combogrid('setValue',adminId);
						jQuery('#admin_id').combogrid('setText',adminName);
					}
				});
				var settings = {
				      flash_url : "<%=contextPath%>/public/swfupload/swfupload.swf",
				      upload_url: "<%=contextPath%>/springMVC/fileUpload/fileupload",
				      post_params: {
				    	 "module" : "<%=com.beaut.project.util.StaticData.XM_MODULE%>"
				      },
				      file_size_limit : "100 MB",
				      file_types : "*.*",
				      file_types_description : "All Files",
				      file_upload_limit : 100,
				      file_queue_limit : 0,
				      custom_settings : {
				        uploadArea : "fsUploadArea",
				        progressTarget : "fsUploadProgress",
				        startButtonId : "btnStart",
				        cancelButtonId : "btnCancel"
				      },
				      debug: false,
				      button_image_url: "<%=contextPath%>/public/swfupload/img/uploadx4.gif",
				      button_width: "65",
				      button_height: "29",
				      button_placeholder_id: "spanButtonUpload",
				      button_text: '<span class=\"textUpload\">上传附件</span>',
				      button_text_style: ".textUpload{color:#0000ff;}",
				      button_text_top_padding : 1,
				      button_text_left_padding : 18,
				      button_width: 80,
				      button_height: 20,
				      button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				      button_cursor: SWFUpload.CURSOR.HAND,
				      
				      file_queued_handler : fileQueued,
				      file_queue_error_handler : fileQueueError,
				      file_dialog_complete_handler : fileDialogComplete,
				      upload_start_handler : uploadStart,
				      upload_progress_handler : uploadProgress,
				      upload_error_handler : uploadError,
				      upload_success_handler : uploadSuccessOver,
				      upload_complete_handler : uploadComplete,
				      queue_complete_handler : queueCompleteOver
				    };
				    swfupload = new SWFUpload(settings);
			   });

				    
		function queueCompleteOver(){
			var attachmentIds = $("attachmentId").value;
		    var attachmentNames = $("attachmentName").value;
		    if(attachmentIds){
		      jQuery('#attaTr').show();
	       	  jQuery('#fsUploadArea').hide();
	       	  if('<%=isShow%>' == 1){
		       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,true,'attach');
		       	  }else{
		       	  	attachMenuUtil("showAtt",null,null,attachmentNames,attachmentIds,false,'attach');
		       	  }
		    }
		 }
		function loadGDSets(){
			var gdIds = $("gdIds").value;
		    var gdNames = $("gdNames").value;
			rtCallBackGDSet(gdIds,gdNames);
		}	
		 function uploadSuccessOver(file, serverData){
				  try {
				    var progress = new FileProgress(file, this.customSettings.progressTarget);
				    progress.toggleCancel(false);
				    var json = null;
				    json = serverData.evalJSON();
				    if(json.rtState=="1") {
				       progress.setError();
				       progress.setStatus("上传失败");
				    } else {
				       if($('attachmentId').value!=null && $('attachmentId').value!=""){
				    	 $('attachmentId').value += ',' + json.rtData.attachmentId;
				       } 
				       else{
				    	   $('attachmentId').value = json.rtData.attachmentId;
				       }
				       if($('attachmentName').value!=null && $('attachmentName').value!=""){
				    	 $('attachmentName').value += '*' + json.rtData.attachmentName;
				       } 
				       else{
				    	   $('attachmentName').value = json.rtData.attachmentName;
				       }
				    }
				  } catch (ex) {
				    this.debug(ex);
				  }
		}
		 			 
		  function deleteAttachment(attachmentId,attachmentName){
			  var attrIds = $("attachmentId").value;
		    var attrNames = $("attachmentName").value;
		     var attrIdArrays = attrIds.split(",");
			  var attrNameArrays = attrNames.split("*");
			 var idArray = new Array();
			 var nameArray = new Array();
			 
			 for(var i=0;i<attrIdArrays.length;i++){
				 if(attrIdArrays[i] != attachmentId){
					 idArray.push(attrIdArrays[i]);
					 nameArray.push(attrNameArrays[i]);
				 }
			 }
			 $("attachmentId").value = idArray.join(",");
			 $("attachmentName").value = nameArray.join("*");
			 if($("attachmentId").value == ""){
				 jQuery('#attaTr').hide();
			 }
		  }
		  
		   function doSubmit() {
		   var hasGds=haveSelect();
			if(hasGds==0){
			alert('项目必须拥有至少一个工单!');
			return;
			}
				//项目基本属性
			 if(jQuery('#xmForm').form('validate')){
			  getALLSubmitSelItems();
			  var xm_id = jQuery('#xm_id').val();
			  var xm_name = jQuery('#xm_name').val();
			  var xm_code = jQuery('#xm_code').val();
			  var construct_code = jQuery('#construct_code').val();
			  var business_type=jQuery('#business_type').combobox('getValue');
			  var specialty_type=jQuery('#specialty_type').combobox('getValue');
			  var specialty_detail=jQuery('#specialty_detail').combobox('getValue');
			 // var gd_code = jQuery('#gd_code').val();
			 // var gd_name = jQuery('#gd_name').val();
			  var xm_depand_id = jQuery('#xm_depand_id').combobox('getValue');
			  var xm_depand_name = jQuery('#xm_depand_id').combobox('getText');
			  var customer_id = jQuery('#customer_id').combogrid('getValue');
			  var customer = jQuery('#customer_id').combogrid('getText');
			  var customer_linkman = jQuery('#customer_linkman').val();
			  var linkman_phone = jQuery('#linkman_phone').val();
			  var company1_id = jQuery('#company1_id').combogrid('getValue');
			  var company1 = encodeURIComponent(jQuery('#company1_id').combogrid('getText'));
			  var company2_id = jQuery('#company2_id').combogrid('getValue');
			  var company2 = encodeURIComponent(jQuery('#company2_id').combogrid('getText'));
			  var customer_dept=jQuery('#customer_dept').val();
			  var admin_id = jQuery('#admin_id').combogrid('getValue');
			  var admin = jQuery('#admin_id').combogrid('getText');
			  var admin_dept_id=jQuery('#admin_dept_id').val();
			  var admin_dept=jQuery('#admin_dept').val();
			  var xm_summary=encodeURIComponent(jQuery('#xm_summary').val());
			  var quantities=encodeURIComponent(jQuery('#quantities').val());
			  var contract_code=jQuery('#contract_code').val();
			  var contract_price=jQuery('#contract_price').numberbox("getValue");
			  var estimate_balance_price=jQuery('#estimate_balance_price').numberbox('getValue');
			  var estimate_work_price=jQuery('#estimate_work_price').val();
              var estimate_material_price=jQuery('#estimate_material_price').val();
              var estimate_other_price=jQuery('#estimate_other_price').val();
              var estimate_manage_price=jQuery('#estimate_manage_price').numberbox('getValue');
              var estimate_tax_price=jQuery('#estimate_tax_price').numberbox('getValue');
              var estimate_grossprofit=jQuery('#estimate_grossprofit').val();
              var estimate_grossprofit_rate=jQuery('#estimate_grossprofit_rate').numberbox('getValue');
			  var attachmentId = jQuery('#attachmentId').val();
			  var no_material = jQuery('#no_material').val();
			  var param = "no_material="+no_material+"&xm_id=<%=xm_id%>&xm_name="+xm_name+"&xm_code="+xm_code+"&construct_code="+construct_code+"&business_type="+business_type+"&specialty_type="+specialty_type+"&specialty_detail="+specialty_detail+"&xm_depand_id="+xm_depand_id
					   +"&xm_depand_name="+xm_depand_name+"&customer_id="+customer_id+"&customer="+customer+"&customer_linkman="+customer_linkman
					   +"&linkman_phone="+linkman_phone+"&admin_id="+admin_id+"&admin="+admin+"&admin_dept_id="+admin_dept_id
					   +"&admin_dept="+admin_dept+"&xm_summary="+xm_summary+"&quantities="+quantities+"&contract_code="+contract_code
					   +"&contract_price="+contract_price+"&estimate_balance_price="+estimate_balance_price+"&estimate_work_price="+estimate_work_price+"&estimate_material_price="+estimate_material_price
					   +"&estimate_other_price="+estimate_other_price+"&estimate_manage_price="+estimate_manage_price+"&estimate_tax_price="+estimate_tax_price+"&customer_dept="+customer_dept+"&company1_id="+company1_id+"&company1="+company1+"&company2_id="+company2_id+"&company2="+company2
					     +"&estimate_grossprofit="+estimate_grossprofit+"&estimate_grossprofit_rate="+estimate_grossprofit_rate+"&attachmentId="+attachmentId+"&subSelValues="+subSelValues+"&subSelTexts="+encodeURIComponent(subSelTexts);
			jQuery.ajax({
				type:'POST',
				<%=isAdd?"url:'"+contextPath+"/springMVC/xm/addXM',":"url:'"+contextPath+"/springMVC/xm/updateXM?xm_id="+xm_id+"',"%>				
				data:param,
				success:function(rtJson){
					if (rtJson.rtState == '0'){
						eval('window.opener.<%=callback%>();');
						window.close();
					}else{
						warningInfo(rtJson.rtMsrg);
					}
				}
			});
		}
		}
		function addGDSet(){
			var estimate_balance_price=jQuery('#estimate_balance_price').numberbox('getValue');
			if(estimate_balance_price==''){
				jQuery.messager.alert("提示","请填写预估结算费用！");
				return ;
			}
			var estimate_manage_price=jQuery('#estimate_manage_price').numberbox('getValue');
			if(estimate_manage_price==''){
				jQuery.messager.alert("提示","请填写预估管理费用！");
				return ;
			}
			var estimate_tax_price=jQuery('#estimate_tax_price').numberbox('getValue');
			if(estimate_tax_price==''){
				jQuery.messager.alert("提示","请填写预估税务费用！");
				return ;
			}
			<%--openDialogResize('<%=contextPath %>/springViews/xm/gdSetSelect.jsp',1000, 800);--%>
			var  tempReturnValue= window.open("<%=contextPath %>/springViews/xm/gdSetSelect.jsp" ,window,'height=1000, width=800, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');

		}
		function rtCallBackGDSet(ids,names){
			  if(ids==""){
				  return;
			  }
			  var sumMoney=0;
			  var sumOtherMoeny=0;
			  var sumBudget=0;
			  var keys= new Array(); 
			  var values= new Array(); 
              keys=ids.split(",");
              values=names.split(",");
              var no_material=0;
			    for (i=0;i<keys.length ;i++ )   
			    {   
					jQuery.ajax({
						type:'GET',
						url:'<%=contextPath %>/springMVC/gd/getGdAssMaterial?gd_id='+keys[i],
						async:false,
						success:function(rtJson){
								sumMoney+=parseFloat(rtJson.sumMoney);
								sumBudget+=parseFloat(rtJson.budget);
								sumOtherMoeny+=parseFloat(rtJson.otherMoney);
						}
					});
			        jsAddItemToSelect(document.getElementById("gdset"),values[i],keys[i]);
			    }     
			    sumMoney = Math.round(sumMoney*Math.pow(10,2))/Math.pow(10,2);
			    sumOtherMoeny = Math.round(sumOtherMoeny*Math.pow(10,2))/Math.pow(10,2);
			    sumBudget = Math.round(sumBudget*Math.pow(10,2))/Math.pow(10,2);
			    jQuery('#gd_num').html(document.getElementById("gdset").options.length);
			    if("<%=isShow%>"!=1){
			    	setCalculateValue(sumMoney,sumOtherMoeny,sumBudget);
			    }	
		}
		
		function setCalculateValue(sumMoney,sumOtherMoeny,sumBudget){
			 if(sumMoney == 0){
					jQuery("#estimate_material_price").val(0);
			}else{
					jQuery("#estimate_material_price").val(sumMoney);
			}
					jQuery("#estimate_other_price").val(sumOtherMoeny);
					jQuery("#estimate_work_price").val(sumBudget);
					var estimate_balance_price=jQuery('#estimate_balance_price').numberbox('getValue');
					var estimate_manage_price=jQuery('#estimate_manage_price').numberbox('getValue');
					var estimate_tax_price=jQuery('#estimate_tax_price').numberbox('getValue');
					var profit=jQuery("#estimate_grossprofit").val();
					
					profit=parseFloat(estimate_balance_price)-parseFloat(estimate_manage_price)-parseFloat(estimate_tax_price)-parseFloat(sumOtherMoeny)-parseFloat(sumMoney)-parseFloat(sumBudget);
					profit = Math.round(profit*Math.pow(10,2))/Math.pow(10,2);
					jQuery("#estimate_grossprofit").val(profit);
					jQuery("#estimate_grossprofit_rate").numberbox("setValue",(parseFloat(profit)/parseFloat(estimate_balance_price)));
		}
		function jsSelectIsExitItem(objSelect, objItemValue) {        
		    var isExit = false;        
		    for (var i = 0; i < objSelect.options.length; i++) {        
		        if (objSelect.options[i].value == objItemValue) {        
		            isExit = true;        
		            break;        
		        }        
		    }        
		    return isExit;        
		}         
   
		// 2.向select选项中 加入一个Item        
		function jsAddItemToSelect(objSelect, objItemText, objItemValue) {        
		    //判断是否存在        
		    if (jsSelectIsExitItem(objSelect, objItemValue)) {        
		       // alert("该Item的Value值已经存在");        
		    } else {        
		        var varItem = new Option(objItemText, objItemValue);      
		        objSelect.options.add(varItem);     
		         
		    }        
		}  
		// 4.删除select中选中的项    
		function jsRemoveSelectedItemFromSelect(objSelect) {        
		    var length = objSelect.options.length - 1;
		    var flag = 0;
		    for(var i = length; i >= 0; i--){    
		        if(objSelect[i].selected == true){    
		            objSelect.options[i] = null;   
		            flag = 1;
		        }    
		    }
		    if(flag == 1){
		    	var ids="";
				var names="";
				if(objSelect.options.length==0){
					jQuery("#estimate_material_price").val(0);
					jQuery("#estimate_other_price").val(0);
					jQuery("#estimate_work_price").val(0);
					jQuery("#estimate_grossprofit").val(0);
					jQuery("#estimate_grossprofit_rate").numberbox("setValue",0);
					return;
				}
			    for(var i = 0; i < objSelect.options.length; i++){  
			    	if(i == objSelect.options.length-1)
					{
						ids+=objSelect.options[i].value;
						names+=objSelect.options[i].text;
					}else
					{
						ids+=objSelect.options[i].value+",";
						names+=objSelect.options[i].text+",";
					}
			    }
			    rtCallBackGDSet(ids,names);
		    }
		} 
		//判断select 是否为0
		function haveSelect(){
		 var length = document.getElementById('gdset').options.length; 
		 return length;
		}
		function clearSel(objSelect){
			objSelect.options.length = 0;  
			jQuery("#estimate_material_price").val(0);
			jQuery("#estimate_other_price").val(0);
			jQuery("#estimate_work_price").val(0);
			jQuery("#estimate_grossprofit").val(0);
			jQuery("#estimate_grossprofit_rate").numberbox("setValue",0);
		}
		 var subSelValues="";
		 var subSelTexts="";
		function getALLSubmitSelItems() {    
			subSelValues="";
			subSelTexts="";
			var objSelect=document.getElementById('gdset');
		         var len=objSelect.options.length;
		    for (var i = 0; i < len; i++) {  
		    	if(i==(len-1))
				{
						subSelValues+=objSelect.options[i].value;
					    subSelTexts+=objSelect.options[i].text;
				}else
				{
					subSelValues+=objSelect.options[i].value+",";
					subSelTexts+=objSelect.options[i].text+",";
					
				}
	       
		    }        
     
		}
		function showGdList(){
				var gd_id=document.getElementById('gdset').value;
			   window.open('<%=contextPath%>/springViews/gd/showGd.jsp?gd_id='+gd_idwindow,"height="+1000+", width="+800+", top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");

		}
		function doSearchc() {
			var searchValue = jQuery('#searchValuec').val();
			var type_id = jQuery('#customer_type_id').combotree('getValue');
			jQuery('#customer_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				type_id : type_id
			});
		}
		function doSearch() {
			var searchValue = jQuery('#searchValue').val();
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			jQuery('#admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id : dept_id
			});
		}
		function selectIsHas(){
			var xm_code = jQuery("#xm_code").val();
			var xm_name = jQuery("#xm_name").val();
			var param = "xm_code="+xm_code+"&xm_name="+xm_name;
			jQuery.ajax({
				type:'GET',
				url:'<%=contextPath %>/springMVC/xm/getXmIsHas',
				data:param,
				dataType:'json',
				success:function(rtJson){
					if(rtJson.rtState == '1'){
					//	jQuery.messager.alert("提示",rtJson.rtMsrg);
					}
				}
			});
		}
		function setCalculateValueBlur(){
					var sumMoney = jQuery("#estimate_material_price").val();
					var sumOtherMoeny = jQuery("#estimate_other_price").val();
					var sumBudget = jQuery("#estimate_work_price").val();
					var estimate_balance_price=jQuery('#estimate_balance_price').numberbox('getValue');
					var estimate_manage_price=jQuery('#estimate_manage_price').numberbox('getValue');
					var estimate_tax_price=jQuery('#estimate_tax_price').numberbox('getValue');
					var profit=jQuery("#estimate_grossprofit").val();
					profit=parseFloat(estimate_balance_price)-parseFloat(estimate_manage_price)-parseFloat(estimate_tax_price)-parseFloat(sumOtherMoeny)-parseFloat(sumMoney)-parseFloat(sumBudget);
					profit = Math.round(profit*Math.pow(10,2))/Math.pow(10,2);
					jQuery("#estimate_grossprofit").val(profit);
					jQuery("#estimate_grossprofit_rate").numberbox("setValue",(parseFloat(profit)/parseFloat(estimate_balance_price)));
		}
		</script>
	</head>
	<body>
		<form id="xmForm" method="post">
		<div style="width:90%;padding-left:50px;margin-top:20px" align="center">

										<input id="no_material"  name="no_material" value="0" type="hidden">
						
							<table  style="border-collapse: collapse;" border="1px" width="100%" bordercolor="#0eb83a" >
							<tr>
									 <td align="right" nowrap class="td1">
										项目名称：
									</td>
									<td class="td2" nowrap >
										<input id="xm_name" name="xm_name"  class="easyui-validatebox" data-options="required:true">
									</td>
									<td align="right" nowrap class="td1">
										项目编号：
									</td>
									<td class="td2" nowrap>
										<input id="xm_code" name="xm_code" class="easyui-validatebox" data-options="required:true" onblur="selectIsHas()">
									</td>
								</tr>
							<tr>
									<td align="right" nowrap class="td1">
										建设单位编号：
									</td>
									<td class="td2" nowrap colspan=3>
										<input id="construct_code" name="construct_code" size=50>
									</td>
								</tr>
	
						        <tr>
									<td align="right" nowrap class="td1">
										业务类别：
									</td>
									<td class="td2" nowrap >
										<input id="business_type"  name="business_type" class="easyui-combobox" data-options="valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=5'" />
									</td>
									 <td align="right" nowrap class="td1">
										专业分类：
									</td>
									<td class="td2" nowrap>
										<input id="specialty_type"  name="specialty_type" class="easyui-combobox" data-options="valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=6'" />
									</td>
								</tr>
								 <tr>
									
									<td align="right" nowrap class="td1">
										专业明细：
									</td>
									<td class="td2" nowrap >
										<input id="specialty_detail"  name="specialty_detail" class="easyui-combobox" data-options="valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=7'" />
									</td>
									 <td align="right" nowrap class="td1">
										立项依据：
									</td>
									<td class="td2" nowrap >
										<input id="xm_depand_id"  name="xm_depand_id" class="easyui-combobox" data-options="required:true,valueField:'id',textField:'text',url:'<%=contextPath %>/springMVC/group/getSystemTypeBox?type=4'" /> 
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										管理公司：
									</td>
									<td class="td2" nowrap >
										<input id="company1_id" name="company1_id" data-options="required:true"/>
									</td>
									<td align="right"  nowrap class="td1">
										实施公司：
									</td>
									<td class="td2" nowrap >
										<input id="company2_id" name="company2_id" data-options="required:true"/>
									</td>
								</tr>
								<tr>
								<td align="right" nowrap class="td1">
										客户：
									</td>
									<td class="td2" nowrap>
										<input id="customer_id" name="customer_id" data-options="required:true">
									</td>
								   <td align="right" nowrap class="td1">
										客户部门：
									</td>
									<td class="td2" nowrap >
										<input id="customer_dept"  name="customer_dept" data-options="required:true">
									</td>
									</tr>
								<tr>
									 <td align="right" nowrap class="td1">
										甲方负责人：
									</td>
									<td class="td2" nowrap>
										<input id="customer_linkman" name="customer_linkman" data-options="required:true">
									</td>
						            <td align="right" nowrap class="td1">
										负责人联系电话：
									</td>
									<td class="td2" nowrap>
										<input id="linkman_phone" name="linkman_phone" data-options="required:true">
									</td>
						
								</tr>
								
								<tr>
									<td align="right"  nowrap class="td1">
										项目负责人：
									</td>
									<td class="td2" nowrap >
										<input type="text" id="admin_id" name="admin_id" data-options="required:true">
									</td>
									<td align="right"  nowrap class="td1">
										所属部门：
									</td>
									<td class="td2" nowrap >
										<input type="hidden" id="admin_dept_id" name="admin_dept_id">
										<input type="text" id="admin_dept" name="admin_dept" readOnly>
									</td>
								</tr>
								
								<tr>
									<td align="right"  nowrap class="td1">
										项目概况：
									</td>
									<td class="td2" nowrap colspan="3">
										<textarea id="xm_summary" name="xm_summary" class="easyui-validatebox" data-options="required:true" style="height:100%;width:100%" rows="6"></textarea>
									</td>
								</tr>
								<tr>
									<td align="right"  nowrap class="td1">
										实物工程量：
									</td>
									<td class="td2" nowrap colspan="3">
										<textarea id="quantities" name="quantities" class="easyui-validatebox" data-options="required:true" style="height:100%;width:100%" rows="6"></textarea>
									</td>
								</tr>
								<tr>
								<td align="right" nowrap class="td1">
										合同编号：
									</td>
									<td class="td2" nowrap >
										<input id=contract_code  name="contract_code" >
									</td>
									 <td align="right" nowrap class="td1">
										合同价：
									</td>
									<td class="td2" nowrap>
										<input id="contract_price" name="contract_price" class="easyui-numberbox" data-options="min:0,precision:2,required:true" value="0"/>
									</td>
						          
								</tr>
								<tr>
						            <td align="right" nowrap class="td1">
									预估结算（审定）价：
									</td>
									<td class="td2" nowrap>
	                                 <input id="estimate_balance_price" name="estimate_balance_price"  class="easyui-numberbox"  data-options="min:0,precision:2,required:true" />
									</td>
									 <td align="right" nowrap class="td1">
										预估施工（劳务）费：
									</td>
									<td class="td2" nowrap>
										<input id="estimate_work_price" name="estimate_work_price" readonly="readonly" value="0"/><span>(工单获取)</span>
									</td>
								</tr>
								<tr>
									
						            <td align="right" nowrap class="td1">
									预估材料采购费：
									</td>
									<td class="td2" nowrap>
	                                 <input id="estimate_material_price" name="estimate_material_price" readonly="readonly"  /><span>(工单获取)</span>
									</td>
									<td align="right" nowrap class="td1">
										预估其他费：
									</td>
									<td class="td2" nowrap>
										<input id="estimate_other_price" name="estimate_other_price" readonly="readonly"   /><span>(工单获取)</span>
									</td>
								</tr>	
						
									<tr>
						            <td align="right" nowrap class="td1">
									预估管理费：
									</td>
									<td class="td2" nowrap>
	                                 <input id="estimate_manage_price" name="estimate_manage_price" class="easyui-numberbox" data-options="min:0,precision:2,required:true"   />
									</td>
									<td align="right" nowrap class="td1">
									预估税费：
									</td>
									<td class="td2" nowrap>
	                                 <input id="estimate_tax_price" name="estimate_tax_price" class="easyui-numberbox" data-options="min:0,precision:2,required:true" />
									</td>
								</tr>	
								<tr>
								<td align="right" nowrap class="td1">
										预算毛利：
									</td>
									<td class="td2" nowrap>
										<input id="estimate_grossprofit" name="estimate_grossprofit" readonly="readonly"  value="0" /><span>(工单获取)</span>
									</td>
						            <td align="right" nowrap class="td1">
									预算毛利率：
									</td>
									<td class="td2" nowrap>
	                                 <input id="estimate_grossprofit_rate" name="estimate_grossprofit_rate" class="easyui-numberbox" data-options="min:0,precision:2" readonly="readonly"  value="0"/><span>(工单获取)</span>
									</td>
								</tr>
								<tr>
								<td align="right" nowrap class="td1">
									包含工单(<span id='gd_num'>0</span>)单机查看详细：
									</td> 
									<td  nowrap colspan="3">
									<input type="hidden" id="gdIds" name="gdIds">
								    <input type="hidden" id="gdNames" name="gdNames">
									<select name="gdset" class="exchangeSelect" multiple="" id="gdset" style="height:200px;width:100%" onclick="showGdList()"></select>
									<BR/>
										<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:false" onclick="addGDSet(this);">选择工单</a>	
									    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:false" onclick="jsRemoveSelectedItemFromSelect(document.getElementById('gdset'));">移除所选工单</a>	
										<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:false" onclick="clearSel(document.getElementById('gdset'));">清空选项</a>	
										
									</td>
						            
								</tr>	
									<tr id="attaTr" style="display:none">
								      <td nowrap class="td1">附件明细: </td>
								      <td class="td2" colspan='3'>
								        <input type="hidden" id="attachmentId" name="attachmentId">
								        <input type="hidden" id="attachmentName" name="attachmentName">
								        <span id="showAtt">
								        </span>
								      </td>
							   	    </tr>
								<tr>
							      <td nowrap  align="right" class="td1">附件：</td>
							      <td class="td2" colspan='3'>
							        	 <div id="fsUploadArea" class="flash" style="width:380px;">
										     <div id="fsUploadProgress"></div>
										     <div>
										       <input type="button" id="btnStart" class="SmallButtonW" value="开始上传" onclick="swfupload.startUpload();" disabled="disabled">&nbsp;&nbsp;
										       <input type="button" id="btnCancel" class="SmallButtonW" value="全部取消" onclick="javascript:swfupload.cancelQueue();jQuery('#fsUploadArea').hide();" disabled="disabled">&nbsp;&nbsp;
										    </div>
									      </div>
									      
										    <div id="attachment1">
									          <span id="spanButtonUpload" title="上传附件"></span>
									        </div>
							      </td>
					   		   </tr>
					   		  <%if(!"1".equals(isShow)){ %>
					   		   <tr>
					<td align="right" nowrap class="td1">
					</td>
					<td  nowrap colspan="5">
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="doSubmit(this);">保存</a>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
					</td>
				</tr>
				<%} %>
				 			</table>	
		</div>
</form>
<div id="tb" style="padding:3px;height:auto">
			<div align="right">
				所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue" name="searchValue" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
<div id="tbc" style="padding:3px;height:auto">
			<div align="right">
				分类：<input  id="customer_type_id" name="customer_type_id" class="easyui-combotree">
				查询条件：<input id="searchValuec" name="searchValuec" style="width:150px" title="客户名称或联系人"/>&nbsp;&nbsp;
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearchc();"></a>
			</div>
		</div>
	</body>
</html>


